package com.igoal.service.dwr;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.igoal.service.CategoryManager;
import com.igoal.service.GoalManager;
import com.igoal.service.SaveResult;

@Service("administrationDWR")
public class AdministrationDWRImpl extends BaseDWRService implements
		AdministrationDWR {
	private GoalManager goalManager;
	private CategoryManager categoryManager;
	
	@Autowired	
	public void setGoalManager(GoalManager goalManager) {
		this.goalManager = goalManager;
	}

	@Autowired	
	public void setCategoryManager(CategoryManager categoryManager) {
		this.categoryManager = categoryManager;
	}

	public int deleteGoal(Long[] goalIds) {
		for(Long goalId : goalIds){
			goalManager.remove(goalId);
		}
		
		return SaveResult.SUCCESS;
	}

	public int disableGoal(Long[] goalIds) {
		for(Long goalId : goalIds){
			goalManager.disable(goalId);
		}
		
		return SaveResult.SUCCESS;
	}
	
	public int enableGoal(Long[] goalIds){
		for(Long goalId : goalIds){
			goalManager.enable(goalId);
		}
		
		return SaveResult.SUCCESS;
	}

	public int updateGoalCategory(Long goalId, Long[] categoryIds) {
		for(Long categoryId : categoryIds){
			goalManager.addGoalToCategory(goalId, categoryId);
		}
		
		return SaveResult.SUCCESS;		
	}

}
